//
//  NSTimer+XDTimer.m
//  iPadAuditAuthorise
//
//  Created by XiangDongMBP on 16/9/19.
//  Copyright © 2016年 XiangDong. All rights reserved.
//

#import "NSTimer+XDTimer.h"

@implementation NSTimer (XDTimer)

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)interval block:(void(^)(NSTimeInterval time))block repeats:(BOOL)repeats {
    return [NSTimer scheduledTimerWithTimeInterval:interval block:block repeats:repeats loopCommonModes:NO];
}


+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)interval block:(void(^)(NSTimeInterval time))block repeats:(BOOL)repeats loopCommonModes:(BOOL)loopCommonModes {
    
    NSTimer *timer = [self scheduledTimerWithTimeInterval:interval target:self selector:@selector(blockInvoke:) userInfo:[block copy] repeats:repeats];
    
    if (loopCommonModes) {
        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    }
    
    return timer;
}


+ (void)blockInvoke:(NSTimer *)timer {
    void (^block)() = timer.userInfo;
    if (block) {
        block([timer timeInterval]);
    }
}

@end
